/**
 * 
 */
package com.knife.security;

/**
 * This is the password complexity enumeration used for PasswordUtil to test
 * password strength. <br/>
 * <br/>
 * Please visit <a
 * href="http://code.google.com/p/java-swiss-knife/">Java-Swiss-Knife</a> and
 * comment, rate, contribute or raise a issue/enhancement for my library. <br/>
 * 
 * @author Anton Van Zyl
 * 
 */
public enum PasswordComplexity {
	
	
	WEAK(5), BELOW_AVERAGE(8), AVERAGE(8), ABOVE_AVERAGE(8), STRONG(12), SECURE(14);

	private int passwordLength = 0;

	private PasswordComplexity(int passwordLength) {
		this.passwordLength = passwordLength;
	}

	/**
	 * Gets the minimum length the specific password type
	 * @return length password
	 */
	public int getPasswordLength() {
		return passwordLength;
	}

	/**
	 * Takes the password complexity score and calculates the correct term that
	 * is used for the complexity of the password.
	 * 
	 * @param score
	 *            - the score calculated in PasswordUtil
	 * @return PasswordComplexity
	 */
	public static PasswordComplexity calculateComplexity(int score) {

		PasswordComplexity passwordComplexity = WEAK;

		if (score < 50) {
			passwordComplexity = WEAK;
		} else if (score >= 50 && score < 60) {
			passwordComplexity = BELOW_AVERAGE;
		} else if (score >= 60 && score < 70) {
			passwordComplexity = AVERAGE;
		} else if (score >= 70 && score < 80) {
			passwordComplexity = ABOVE_AVERAGE;
		} else if (score >= 80 && score < 100) {
			passwordComplexity = STRONG;
		} else if (score >= 100) {
			passwordComplexity = SECURE;
		}

		return passwordComplexity;
	}

}
